//
//  Infor_Main_ViewController.m
//  Pacific_Computer
//
//  Created by 范琦 on 14-12-17.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "Infor_Main_ViewController.h"
#import "Infor_Search_ViewController.h"
#import "InforCollecCell.h"
#import "UIColor+AddColor.h"
#import "InforCell.h"
#import "Infor_Main_detail.h"
#import "UIImageView+WebCache.h"
#import "Infor_Photo_Cell.h"
#import "UIScrollView+MJRefresh.h"
#import "UIScrollView+Extension.h"
#import "NetHandler.h"
#import "Infor_details_ViewController.h"
#import "AJComboBox.h"
#import "Reachability.h"
#import "MBProgressHUD.h"

@interface Infor_Main_ViewController ()<UICollectionViewDataSource,UICollectionViewDelegate, UICollectionViewDelegateFlowLayout, UIScrollViewDelegate, UITableViewDataSource,UITableViewDelegate>
@property(nonatomic, retain) NSMutableArray *nowArr;
@property(nonatomic, retain) NSMutableArray *willArr;
@property(nonatomic, retain) UICollectionView *collect;
// 箭头按钮 弹出collect
@property(nonatomic, retain) UIButton *changeButton;
@property(nonatomic, retain) UIScrollView *scrollAll;
// 五张大图的scroll
@property(nonatomic, retain) UIScrollView *scrollPhotos;
@property(nonatomic, retain) UIPageControl *pageCon;

@property(nonatomic, retain) UIScrollView *nowScroll;

@property(nonatomic, retain) UIView *view1;
// table
@property(nonatomic, retain) UITableView *table;
// table的数据源
@property(nonatomic, retain) NSMutableArray *tableArr;

// 用来判断collect弹出还是收起
@property(nonatomic, assign) BOOL change;

@property(nonatomic, assign) NSInteger i;

// 所有栏目的名字数组
@property(nonatomic, retain) NSMutableArray *arrAll;
// 所有栏目的请求拼接数组
@property(nonatomic, retain) NSMutableArray *arrRequest;
///table的偏移量记录
@property(nonatomic, assign) NSInteger tableCon;

@property(nonatomic, retain) NSMutableArray *photoArr;

@property(nonatomic, retain) MBProgressHUD *hud;

@end

@implementation Infor_Main_ViewController

-(void)dealloc
{
    [_photoArr release];
    [_pageCon release];
    [_nowArr release];
    [_willArr release];
    [_collect release];
    [_scrollAll release];
    [_scrollPhotos release];
    [_nowScroll release];
    [_hud release];
    [_view1 release];
    [_table release];
    [_tableArr release];
    [_arrAll release];
    [_arrRequest release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.i = 0;
    self.navigationController.navigationBar.tintColor  = [UIColor hongse];
    
    // Do any additional setup after loading the view.
    self.change = YES;
    self.nowArr = [NSMutableArray arrayWithObjects:@"头条",@"MID",@"相机", nil];
    self.willArr = [NSMutableArray arrayWithObjects:@"新闻",@"评测",@"摄像机", @"平板", @"企业", @"导购", @"笔记本", @"电视", @"行情", @"iPhone", @"超极本", @"手机", @"直播", @"DIY", @"家电", nil];
    self.arrAll = [NSMutableArray arrayWithObjects:@"头条", @"电视", @"新闻", @"相机", @"超极本", @"DIY", @"家电", @"行情", @"MID", @"平板", @"评测", @"手机", @"笔记本", @"摄像机", @"iPhone", @"企业", @"导购", nil];
    self.arrRequest = [NSMutableArray arrayWithObjects:@"1", @"900", @"2",@"500", @"301", @"120",@"600",@"440100", @"700", @"400", @"4", @"200", @"300", @"800", @"5", @"130", @"3", nil];
    
    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(search:)] autorelease];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    
    // 总的滚动视图
    self.scrollAll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 40, self.view.bounds.size.width, self.view.bounds.size.height - 30)];
    self.scrollAll.contentSize = CGSizeMake([self.nowArr count] * self.view.bounds.size.width, 0);
    self.scrollAll.pagingEnabled = YES;
    self.scrollAll.multipleTouchEnabled = YES;
    self.scrollAll.delegate = self;
    [self.view addSubview:self.scrollAll];
    self.scrollAll.backgroundColor = [UIColor whiteColor];
    [_scrollAll release];
    
    self.changeButton = [UIButton buttonWithType:UIButtonTypeSystem];

//    UIView *viewhx = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 50, 0, 1, 40)];
//    [self.view addSubview:viewhx];
//    viewhx.backgroundColor = [UIColor shenhuiseColor];
//    [viewhx release];
//    UIView *viewzx = [[UIView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 50, 39, 50, 1)];
//    [self.view addSubview:viewzx];
//    viewzx.backgroundColor = [UIColor shenhuiseColor];
//    [viewzx release];
//    
    
    
    [self.view addSubview:self.changeButton];
    self.changeButton.backgroundColor = [UIColor clearColor];
    self.changeButton.frame = CGRectMake(self.view.bounds.size.width - 40, 5, 35, 35);
    
    [self.changeButton addTarget:self action:@selector(change:) forControlEvents:UIControlEventTouchUpInside];
    [self.changeButton setImage:[UIImage imageNamed:@"arrows.png"] forState:UIControlStateNormal];
    self.changeButton.tintColor = [UIColor hongse];

    
    // 现有的栏目的滚动视图
    self.nowScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width - 40, 40)];
    self.nowScroll.contentSize = CGSizeMake([self.nowArr count] * 80, 0);
    [self.view addSubview:self.nowScroll];
    self.nowScroll.backgroundColor = [UIColor whiteColor];
    [_nowScroll release];
    
    for (int i = 0; i < [self.nowArr count]; i++) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
        button.frame = CGRectMake(i * 55 + (i * 20), 0, 65, 40);
        [self.nowScroll addSubview:button];
        [button setTitle:[self.nowArr objectAtIndex:i] forState:UIControlStateNormal];
        button.backgroundColor = [UIColor whiteColor];
        [button addTarget:self action:@selector(nowButton:) forControlEvents:UIControlEventTouchUpInside];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.tintColor = [UIColor blackColor];
        
        // button下方蓝色的view
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 37, button.bounds.size.width, 3)];
        view.backgroundColor = [UIColor whiteColor];
        [button addSubview:view];
        if ([[self.nowArr objectAtIndex:i]isEqualToString:@"头条"]) {
            view.backgroundColor = [UIColor hongse];
            button.tintColor = [UIColor hongse];
        }
        view.tag = 1000 + i;
        button.tag = 10000 + i;
        [view release];
        
    }
    // collection 承载button
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    
    flowLayout.scrollDirection =UICollectionViewScrollDirectionVertical;
    flowLayout.minimumLineSpacing = 20;
    flowLayout.minimumInteritemSpacing = 20;
    flowLayout.headerReferenceSize = CGSizeMake(self.view.bounds.size.width, 20);
    flowLayout.itemSize = CGSizeMake(55, 25);

    self.view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 0)];
    [self.view addSubview:self.view1];
    self.view1.backgroundColor = [UIColor clearColor];
    self.view1.clipsToBounds = YES;
    [_view1 release];
    self.collect = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height / 2) collectionViewLayout:flowLayout];
    self.collect.delegate = self;
    self.collect.dataSource = self;
    self.collect.backgroundColor = [UIColor huiseColor];
    [self.view1 addSubview:self.collect];
    [_collect release];
    
    [flowLayout release];
    // 给collect注册cell
    [self.collect registerClass:[InforCollecCell class] forCellWithReuseIdentifier:@"collect"];
    // 给collect注册一个view
    [self.collect registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"];
    
    // 循环创建每个小scroll
    for (int i = 0; i < [self.nowArr count]; i++) {
 
            
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.view.bounds.size.height - self.view.bounds.size.height * 1 / 4)];
            [self.scrollAll addSubview:view];
            view.tag = i + 100;
            [view release];
        

    }
    self.hud = [[MBProgressHUD alloc]initWithView:self.view];
    [self.hud setMode:MBProgressHUDModeIndeterminate];
    
    self.hud.labelText = @"loading...";
    [self.hud show:YES];
    [self.view addSubview:_hud];
    
    [_hud release];
    self.tableCon = self.scrollAll.contentOffset.x;
    [self reload];
    [self setupRefresh];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    // 视图将要出现时, 将navigationBar 的hidden设置为NO
    self.navigationController.navigationBarHidden = NO;
    
    // 判断网络字符串是否为空
    if ([self GetCurrntNet]) {
        // 不为空, 则处理网络数据
        // 调用数据处理方法
        [self setupRefresh];
        [self reload];
        [self.hud removeFromSuperview];
        
    }else {
        // 否则检查网络
        self.hud.labelText = @"请检查您的网络";
    }
    // 刷新数据
    [self.table reloadData];
    
}
-(NSString*) GetCurrntNet
{
    NSString* result;
    Reachability *r = [Reachability reachabilityWithHostname:@"www.apple.com"];
    switch ([r currentReachabilityStatus]) {
        case NotReachable:     // 没有网络连接
            result=nil;
            break;
        case ReachableViaWWAN: // 使用3G网络
            result=@"3G";
            break;
        case ReachableViaWiFi: // 使用WiFi网络
            result=@"WiFi";
            break;
    }
    return result;
}
// photos自动循环的方法
- (void)photosG:(NSTimer *)timer
{
    if (self.i == 0) {
        self.scrollPhotos.contentOffset = CGPointMake((self.pageCon.currentPage + 1) * self.view.bounds.size.width, 0);
        self.pageCon.currentPage = self.scrollPhotos.contentOffset.x / self.view.bounds.size.width;
        self.i++;
    }
    else{
        if (self.pageCon.currentPage == 4) {
            self.pageCon.currentPage = 0;
        }
        if (self.pageCon.currentPage == 0) {
            self.scrollPhotos.contentOffset = CGPointMake(self.pageCon.currentPage * self.view.bounds.size.width, 0);
            self.pageCon.currentPage = self.scrollPhotos.contentOffset.x / self.view.bounds.size.width;
        }
        else{
            self.scrollPhotos.contentOffset = CGPointMake((self.pageCon.currentPage + 1) * self.view.bounds.size.width, 0);
            self.pageCon.currentPage = self.scrollPhotos.contentOffset.x / self.view.bounds.size.width;
        }
    }

}
// 下拉刷新加载==========================
- (void)setupRefresh
{
    //    NSLog(@"进入了setupRefresh");
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    
    [self.table addHeaderWithTarget:self action:@selector(headerRereshing)];
    //进入刷新状态(一进入程序就下拉刷新)
    [self.table headerBeginRefreshing];
    
    
    // 2.上拉加载更多(进入刷新状态就会调用self的footerRereshing)
    [self.table addFooterWithTarget:self action:@selector(footerRereshing)];
}
- (void)headerRereshing
{
    //1. 在这调用请求网络数据方法（刷新数据）
    if (self.scrollAll.contentOffset.x == 0) {
        NSString *str = @"http://mrobot.pconline.com.cn/v2/cms/channels/1?pageNo=1&pageSize=20";
        str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [NetHandler getDataWithUrl:str completion:^(NSData *data) {
            NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *path = [NSString stringWithFormat:@"%@/%lu.aa", docPath, (unsigned long)[str hash]];

            if (data != nil) {
                BOOL result1 = [NSKeyedArchiver archiveRootObject:data toFile:path];
                NSLog(@"%d", result1);
                id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                NSArray *arr = [result objectForKey:@"focus"];
                NSArray *tableArr = [result objectForKey:@"articleList"];
                [self.tableArr removeAllObjects];
                for (NSDictionary *dic in tableArr) {
                    Infor_Main_detail *detail = [[Infor_Main_detail alloc]init];
                    [detail setValuesForKeysWithDictionary:dic];
                    [self.tableArr addObject:detail];
                    [detail release];
                }
                self.photoArr = [NSMutableArray array];
                for (int i = 0; i < [arr count]; i++) {
                    NSDictionary *dicc = [arr objectAtIndex:i];
                    [self.photoArr addObject:dicc];
                    NSString *strr = [dicc objectForKey:@"image"];
                    NSURLResponse *response = nil;
                    strr = [strr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strr] cachePolicy:  NSURLRequestUseProtocolCachePolicy timeoutInterval:20];
                    req.HTTPMethod = @"GET";
                    NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:nil];

                    NSString *pathh = [NSString stringWithFormat:@"%@/%lu.aa", docPath, (unsigned long)[strr hash]];


                    if (data != nil) {
                        BOOL resultt = [NSKeyedArchiver archiveRootObject:data toFile:pathh];
                        NSLog(@"%d", resultt);
                        UIImage *image = [UIImage imageWithData:data];
                        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                        imageV.image = image;
                        [self.scrollPhotos addSubview:imageV];
                        [imageV release];
                    }else{
                        NSData *picData = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
                        if (picData != nil) {
                            UIImage *image = [UIImage imageWithData:picData];
                            UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                            imageV.image = image;
                            [self.scrollPhotos addSubview:imageV];
                            [imageV release];
                        }
                    }
                }
            }
            else{
                NSData *pickData = [NSKeyedUnarchiver unarchiveObjectWithFile:path];;
                if (pickData != nil) {
                    id result = [NSJSONSerialization JSONObjectWithData:pickData options:NSJSONReadingMutableContainers error:nil];
                    NSArray *arr = [result objectForKey:@"focus"];
                    NSArray *tableArr = [result objectForKey:@"articleList"];
                    [self.tableArr removeAllObjects];
                    for (NSDictionary *dic in tableArr) {
                        Infor_Main_detail *detail = [[Infor_Main_detail alloc]init];
                        [detail setValuesForKeysWithDictionary:dic];
                        [self.tableArr addObject:detail];
                        [detail release];
                    }
                    for (int i = 0; i < [arr count]; i++) {
                        NSDictionary *dicc = [arr objectAtIndex:i];
                        NSString *strr = [dicc objectForKey:@"image"];
                        NSURLResponse *response = nil;
                        strr = [strr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                        NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20];
                        req.HTTPMethod = @"GET";
                        NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:nil];

                        NSString *pathh = [NSString stringWithFormat:@"%@/%lu.aa", docPath, (unsigned long)[strr hash]];


                        if (data != nil) {
                            BOOL resultt = [NSKeyedArchiver archiveRootObject:data toFile:pathh];
                            NSLog(@"%d", resultt);
                            UIImage *image = [UIImage imageWithData:data];
                            UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                            imageV.image = image;
                            [self.scrollPhotos addSubview:imageV];
                            [imageV release];
                        }else{
                            NSData *picData = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
                            if (picData != nil) {
                                UIImage *image = [UIImage imageWithData:picData];
                                UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                                imageV.image = image;
                                [self.scrollPhotos addSubview:imageV];
                                [imageV release];
                            }
                        }
                    }
                }
            }
        }];
    }
    else{
        NSInteger a = self.scrollAll.contentOffset.x / self.view.bounds.size.width;
        NSString *str = [self.nowArr objectAtIndex:a];
        NSString *sttr = @"";
        for (int i = 0; i < [self.arrAll count]; i++) {
            NSString *strr = [self.arrAll objectAtIndex:i];
            if ([strr isEqualToString:str]) {
                sttr = [self.arrRequest objectAtIndex:i];
            }
        }
        NSString *str1 = [NSString stringWithFormat:@"http://mrobot.pconline.com.cn/v2/cms/channels/%@?pageNo=1&pageSize=20", sttr];
        str1 = [str1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        [NetHandler getDataWithUrl:str1 completion:^(NSData *data) {
            id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSArray *arr = [result objectForKey:@"focus"];
            NSArray *tableArr = [result objectForKey:@"articleList"];
            [self.tableArr removeAllObjects];
            for (NSDictionary *dic in tableArr) {
                Infor_Main_detail *detail = [[Infor_Main_detail alloc]init];
                [detail setValuesForKeysWithDictionary:dic];
                [self.tableArr addObject:detail];
                [detail release];
            }
            for (int i = 0; i < [arr count]; i++) {
                NSDictionary *dicc = [arr objectAtIndex:i];
                NSString *strr = [dicc objectForKey:@"image"];
                NSURLResponse *response = nil;
                strr = [strr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20];
                req.HTTPMethod = @"GET";
                NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:nil];
                NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

                NSString *path = [NSString stringWithFormat:@"%@/%lu.aa", docPath, (unsigned long)[strr hash]];



                if (data != nil) {
                    BOOL result1 = [NSKeyedArchiver archiveRootObject:data toFile:path];
                    NSLog(@"%d", result1);
                    UIImage *image = [UIImage imageWithData:data];
                    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                    imageV.image = image;
                    [self.scrollPhotos addSubview:imageV];
                    [imageV release];
                }
                else{
                    NSData *pickData = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
                    if (pickData != nil) {
                        UIImage *image = [UIImage imageWithData:pickData];
                        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                        imageV.image = image;
                        [self.scrollPhotos addSubview:imageV];
                        [imageV release];
                    }
                }
            }
        }];
    }
    
    //2. 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
        [self.table reloadData];
        
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.table headerEndRefreshing];
    });
}

//   进入加载状态
- (void)footerRereshing
{
    //1. 拼接口等操作
    // 请求加载数据
    NSInteger a = [self.tableArr count]/20;
    NSString *str = [NSString stringWithFormat:@"http://mrobot.pconline.com.cn/v2/cms/channels/1?pageNo=%ld&pageSize=20",a + 1];
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [NetHandler getDataWithUrl:str completion:^(NSData *data) {
        id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSArray *arr = [result objectForKey:@"focus"];
        NSArray *tableArr = [result objectForKey:@"articleList"];
        for (NSDictionary *dic in tableArr) {
            Infor_Main_detail *detail = [[Infor_Main_detail alloc]init];
            [detail setValuesForKeysWithDictionary:dic];
            [self.tableArr addObject:detail];
            [detail release];
        }
        for (int i = 0; i < [arr count]; i++) {
            NSDictionary *dicc = [arr objectAtIndex:i];
            NSString *strr = [dicc objectForKey:@"image"];
            NSURLResponse *response = nil;
            strr = [strr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
            NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20];
            req.HTTPMethod = @"GET";
            NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:nil];
            NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
            NSString *path = [NSString stringWithFormat:@"%@/%lu.aa", docPath, (unsigned long)[strr hash]];


            if (data != nil) {
                BOOL result1 = [NSKeyedArchiver archiveRootObject:data toFile:path];
                NSLog(@"%d", result1);
                UIImage *image = [UIImage imageWithData:data];
                UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                imageV.image = image;
                [self.scrollPhotos addSubview:imageV];
                [imageV release];
            }
            else{
                NSData *pickData = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
                if (pickData != nil) {
                    UIImage *image = [UIImage imageWithData:pickData];
                    UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                    imageV.image = image;
                    [self.scrollPhotos addSubview:imageV];
                    [imageV release];
                }
            }
        }
    }];
    
    // 2.2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        // 刷新表格
        
        // (最好在刷新表格后调用)调用endRefreshing可以结束刷新状态
        [self.table reloadData];
        [self.table footerEndRefreshing];
    });
}

// collect的section的个数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 2;
}

// 已经停止减速 协议
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView == self.scrollAll) {
        
        NSInteger i = scrollView.contentOffset.x / self.view.bounds.size.width;

        UIView *view = [self.view viewWithTag:i + 1000];
        UIButton *button = (UIButton *)[self.view viewWithTag:i + 10000];
        button.tintColor = [UIColor hongse];
        view.backgroundColor = [UIColor hongse];
        
        for (int i1 = 1000; i1 < [self.nowArr count] + 1001; i1++) {
            UIView *view = [self.view viewWithTag:i1];
            if (i1 != i + 1000) {
                view.backgroundColor = [UIColor whiteColor];
                UIButton *buttonak = (UIButton *)[self.view viewWithTag:i1 + 9000];
                buttonak.tintColor = [UIColor blackColor];
            }
        }
        if (i > 4) {
            self.nowScroll.contentOffset = CGPointMake((i - 4) * (self.view.bounds.size.width / 5), 0);
        }
        if (i == 0) {
            self.nowScroll.contentOffset = CGPointMake(0, 0);
        }
        // 向右翻动大页面
        if (self.tableCon != self.scrollAll.contentOffset.x) {
            
            [self.tableArr removeAllObjects];
            
            UIView *view1 = [self.view viewWithTag:i + 100];
            
            for (UIView *vieww in [view1 subviews]) {
                [vieww removeFromSuperview];
                
            }
            
            
            
            for (UIView *vview in [self.table subviews]) {
                [vview removeFromSuperview];
            }
            self.tableCon = self.scrollAll.contentOffset.x;
            [self reload];
            [self setupRefresh];
        }
        
        
    }
    else if (scrollView == self.scrollPhotos){
       NSInteger i = scrollView.contentOffset.x / self.view.bounds.size.width;
        self.pageCon.currentPage = i;
    }
}
- (void)bbphoto:(UIButton *)button
{
    Infor_details_ViewController *detail = [[Infor_details_ViewController alloc]init];
    detail.dic = [self.photoArr objectAtIndex:self.pageCon.currentPage];
    [self.navigationController pushViewController:detail animated:YES];
    [detail release];
    
}

- (void)reload
{
    self.tableArr = [NSMutableArray array];
    if (self.scrollAll.contentOffset.x == 0) {
        
        self.scrollPhotos = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.scrollAll.bounds.size.height * 1 / 3)];
        self.scrollPhotos.contentSize = CGSizeMake(self.view.bounds.size.width * 5, 0);
        self.scrollPhotos.pagingEnabled = YES;
        self.scrollPhotos.bounces = NO;
        self.scrollPhotos.delegate = self;
        for (int i = 0; i < 5; i++) {
            UIButton *bb = [UIButton buttonWithType:UIButtonTypeSystem];
            bb.frame = CGRectMake(i * self.scrollPhotos.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height);
            bb.backgroundColor = [UIColor clearColor];
            [self.scrollPhotos addSubview:bb];
            [bb addTarget:self action:@selector(bbphoto:) forControlEvents:UIControlEventTouchUpInside];
        }
        
        UIView *view = (UIView *)[self.view viewWithTag:100];
        self.table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, view.bounds.size.width, view.bounds.size.height) style:UITableViewStylePlain];
        [view addSubview:self.table];
        self.table.dataSource = self;
        self.table.delegate = self;
        self.table.rowHeight = 100;
        [_scrollPhotos release];
        [_table release];
        UIView *vieww = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
        [vieww addSubview:self.scrollPhotos];
        vieww.tag = 500;
        self.table.tableHeaderView = vieww;
        self.table.contentSize = CGSizeMake(0, [self.tableArr count] * 150 + 200);
        [NSTimer scheduledTimerWithTimeInterval:2.5f target:self selector:@selector(photosG:) userInfo:nil repeats:YES];
        
        [vieww release];
        // pageCon 五张图片的下点
        self.pageCon = [[UIPageControl alloc]initWithFrame:CGRectMake(self.view.bounds.size.width - 70, self.scrollPhotos.bounds.size.height * 6 / 7 - 5, 50, 30)];
        self.pageCon.backgroundColor = [UIColor clearColor];
        self.pageCon.numberOfPages = 5;
        // 当前选择的点的颜色
        self.pageCon.currentPageIndicatorTintColor = [UIColor whiteColor];
        // 所有点的颜色
        self.pageCon.pageIndicatorTintColor = [UIColor shenhuiseColor];
        [self.pageCon addTarget:self action:@selector(photoChange:) forControlEvents:UIControlEventValueChanged];
        
        [self.table.tableHeaderView addSubview:self.pageCon];
        
        [_pageCon release];
        
        NSString *str = @"http://mrobot.pconline.com.cn/v2/cms/channels/1?pageNo=1&pageSize=20";
        str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:str] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20];
        request.HTTPMethod = @"GET";
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];

            NSString *path = [NSString stringWithFormat:@"%@/%lu.aa", docPath, (unsigned long)[str hash]];



            if (data != nil) {
                BOOL result1 = [NSKeyedArchiver archiveRootObject:data toFile:path];
                NSLog(@"%d", result1);
                NSDictionary *result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
                NSArray *arr = [result objectForKey:@"focus"];
                NSArray *tableArr = [result objectForKey:@"articleList"];
                for (NSDictionary *dic in tableArr) {
                    Infor_Main_detail *detail = [[Infor_Main_detail alloc]init];
                    [detail setValuesForKeysWithDictionary:dic];
                    [self.tableArr addObject:detail];
                    [detail release];
                }
                for (int i = 0; i < [arr count]; i++) {
                    NSDictionary *dicc = [arr objectAtIndex:i];
                    NSString *strr = [dicc objectForKey:@"image"];
                    NSURLResponse *response = nil;
                    strr = [strr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20];
                    req.HTTPMethod = @"GET";
                    NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:nil];

                    NSString *pathh = [NSString stringWithFormat:@"%@/%lu.aa", docPath, (unsigned long)[strr hash]];



                    if (data != nil) {
                        BOOL result1 = [NSKeyedArchiver archiveRootObject:data toFile:pathh];
                        NSLog(@"%d", result1);
                        UIImage *image = [UIImage imageWithData:data];
                        UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                        imageV.image = image;
                        [self.scrollPhotos addSubview:imageV];
                        [imageV release];
                    }else{
                        NSData *pickData = [NSKeyedUnarchiver unarchiveObjectWithFile:pathh];
                        if (pickData != nil) {
                            UIImage *image = [UIImage imageWithData:pickData];
                            UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                            imageV.image = image;
                            [self.scrollPhotos addSubview:imageV];
                            [imageV release];
                        }
                    }
                }
            }else{
                NSData *pickData = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
                if (pickData != nil) {
                    NSDictionary *result = [NSJSONSerialization JSONObjectWithData:pickData options:NSJSONReadingMutableContainers error:nil];
                    NSArray *arr = [result objectForKey:@"focus"];
                    NSArray *tableArr = [result objectForKey:@"articleList"];
                    for (NSDictionary *dic in tableArr) {
                        Infor_Main_detail *detail = [[Infor_Main_detail alloc]init];
                        [detail setValuesForKeysWithDictionary:dic];
                        [self.tableArr addObject:detail];
                        [detail release];
                    }
                    for (int i = 0; i < [arr count]; i++) {
                        NSDictionary *dicc = [arr objectAtIndex:i];
                        NSString *strr = [dicc objectForKey:@"image"];
                        NSURLResponse *response = nil;
                        strr = [strr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                        NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20];
                        req.HTTPMethod = @"GET";
                        NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:nil];

                        NSString *pathh = [NSString stringWithFormat:@"%@/%lu.aa", docPath, (unsigned long)[strr hash]];



                        if (data != nil) {
                            BOOL result1 = [NSKeyedArchiver archiveRootObject:data toFile:pathh];
                            NSLog(@"%d", result1);
                            UIImage *image = [UIImage imageWithData:data];
                            UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                            imageV.image = image;
                            [self.scrollPhotos addSubview:imageV];
                            [imageV release];
                        }else{
                            NSData *pickData = [NSKeyedUnarchiver unarchiveObjectWithFile:pathh];
                            if (pickData != nil) {
                                UIImage *image = [UIImage imageWithData:pickData];
                                UIImageView *imageV = [[UIImageView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.scrollPhotos.bounds.size.height)];
                                imageV.image = image;
                                [self.scrollPhotos addSubview:imageV];
                                [imageV release];
                            }
                        }
                    }
                }
            }
            
        }];
    }
    else{
        NSInteger a = self.scrollAll.contentOffset.x / self.view.bounds.size.width;
        UIView *view1 = [self.view viewWithTag:100 + a];
        self.table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, view1.bounds.size.height) style:UITableViewStylePlain];
        self.table.delegate = self;
        self.table.dataSource = self;
        [view1 addSubview:self.table];
        [_table release];
        self.table.rowHeight = 100;
    }

}

// 当五张图片变化
- (void)photoChange:(UIPageControl *)page
{
    [self.scrollPhotos setContentOffset:CGPointMake(page.currentPage * self.view.bounds.size.width, 0) animated:YES];

}


// section
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *label = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"head" forIndexPath:indexPath];
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 30)];
    label1.font = [UIFont systemFontOfSize:13];
    if (indexPath.section == 0) {
        label1.text = @"现有栏目, 拖动标签可以调整顺序";
        label1.backgroundColor = [UIColor whiteColor];
        [label addSubview:label1];
        return label;
    }
    else{
        label1.text = @"更多栏目, 点击标签进行添加";
        label1.backgroundColor = [UIColor huiseColor];
        [label addSubview:label1];
        return label;
    }

}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    return CGSizeMake(self.view.bounds.size.width, 30);
    
}

// collecttion的cell数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (section == 0) {
        
        return [self.nowArr count];
    }
    else{
        return [self.willArr count];
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    InforCollecCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collect" forIndexPath:indexPath];
    if (indexPath.section == 0) {
        NSString *str = [self.nowArr objectAtIndex:indexPath.row];
        [cell.button setTitle:str forState:UIControlStateNormal];
        cell.button.backgroundColor = [UIColor whiteColor];
        cell.button.titleLabel.font = [UIFont systemFontOfSize:13];
        cell.button.tintColor = [UIColor blackColor];
        cell.button.layer.cornerRadius = 3;
        [cell.button addTarget:self action:@selector(button1:) forControlEvents:UIControlEventTouchUpInside];
        if ([str isEqualToString:@"头条"]) {
            cell.button.enabled = NO;
        }
        return cell;
    }
    else{
        NSString *str = [self.willArr objectAtIndex:indexPath.row];
        [cell.button setTitle:str forState:UIControlStateNormal];
        cell.button.backgroundColor = [UIColor whiteColor];
        cell.button.tintColor = [UIColor hongse];
        cell.button.layer.cornerRadius = 5;
        cell.button.titleLabel.font = [UIFont systemFontOfSize:13];
        [cell.button addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];

        return cell;
    }
}
// tableView的协议方法!!!!!!!!!!!!!!
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.tableArr count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    InforCell *cell = [tableView dequeueReusableCellWithIdentifier:@"a"];
    if (cell == nil) {
        cell = [[[InforCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"a"]autorelease];
    }
    Infor_Main_detail *detail = [self.tableArr objectAtIndex:indexPath.row];
    NSString *str = detail.image;
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [cell.imagev setImageWithURL:[NSURL URLWithString:str]];
    cell.mainLabel.text = detail.title;
    cell.mainLabel.numberOfLines = 0;
    cell.mainLabel.font = [UIFont systemFontOfSize:15];
    cell.time.text = detail.pubDate;
    cell.time.font = [UIFont systemFontOfSize:12];
    NSString *strr = [detail.cmtCount description];
    NSString *sttr = [NSString stringWithFormat:@"%@条",strr];
    cell.count.text = sttr;
    cell.count.font = [UIFont systemFontOfSize:12];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    Infor_details_ViewController *infor = [[Infor_details_ViewController alloc]init];
    Infor_Main_detail *main = [self.tableArr objectAtIndex:indexPath.row];
    infor.infor = main;
    NSUserDefaults *uf = [NSUserDefaults standardUserDefaults];
    NSArray *arr = [uf objectForKey:@"now"];
    if (arr.count == 0) {
        arr = [NSArray array];
    }
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setObject:main.url forKey:main.title];
    arr = [arr arrayByAddingObject:dic];
    [uf setObject:arr forKey:@"now"];
    [self.navigationController pushViewController:infor animated:YES];
    [infor release];
}




//    所有的按钮方法
// 点击nowButton的方法
- (void)nowButton:(UIButton *)button
{
    NSInteger i = button.frame.origin.x / 75;
    UIView *view = [self.view viewWithTag:i + 1000];
    view.backgroundColor = [UIColor hongse];
    button.tintColor = [UIColor hongse];
    for (int i1 = 1000; i1 < [self.nowArr count] + 1001; i1++) {
        UIView *view = [self.view viewWithTag:i1];
        
        
        
        if (i1 != i + 1000) {
            view.backgroundColor = [UIColor whiteColor];
            UIButton *button = (UIButton *)[self.view viewWithTag:9000+i1];
            button.tintColor = [UIColor blackColor];
        }
    }
    self.scrollAll.contentOffset = CGPointMake(i * self.view.bounds.size.width, 0);
    [self.tableArr removeAllObjects];
    for (UIView *vview in [self.table subviews]) {
        [vview removeFromSuperview];
    }
    
    
    
    self.tableCon = self.scrollAll.contentOffset.x;
    [self reload];
    [self setupRefresh];
    
    
    
}


// 从已经有了的数组移除
- (void)button1:(UIButton *)button
{
    [self.willArr addObject:button.titleLabel.text];
    [self.nowArr removeObject:button.titleLabel.text];
    [self.collect reloadData];
}


// 从将要添加的数组 添加到 已经有了的数组中
- (void)button:(UIButton *)button
{
    [self.nowArr addObject:button.titleLabel.text];
    [self.willArr removeObject:button.titleLabel.text];
    [self.collect reloadData];

}
// 改变collect的弹出和收起
- (void)change:(UIButton *)button
{
    if (self.change == YES) {
        [UIView animateWithDuration:0.5 animations:^{
            self.view1.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
        }];
        
        self.changeButton.transform = CGAffineTransformMakeRotation(M_PI);
 
        [self.view bringSubviewToFront:self.changeButton];
        self.change = NO;
    }
    else{
        [UIView animateWithDuration:0.3 animations:^{
            
            self.view1.frame =   CGRectMake(0, 0, self.view.bounds.size.width, 0);
            self.changeButton.transform = CGAffineTransformMakeRotation(0);
            
        }];
        self.change = YES;
        // 选择栏目 返回时候 移除之前的子视图
        for (UIView *view in [self.nowScroll subviews]) {
            [view removeFromSuperview];
        }
        
        // 添加所有选择的button
        for (int i = 0; i < [self.nowArr count]; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = CGRectMake(i * 55 + (i * 20), 0, 65, 40);
            [self.nowScroll addSubview:button];
            [button setTitle:[self.nowArr objectAtIndex:i] forState:UIControlStateNormal];
            button.backgroundColor = [UIColor whiteColor];
            [button addTarget:self action:@selector(nowButton:) forControlEvents:UIControlEventTouchUpInside];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            button.tintColor = [UIColor blackColor];
            
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, button.bounds.size.height *92.5 / 100, button.bounds.size.width, button.bounds.size.height * 7.5 / 100)];
            view.backgroundColor = [UIColor whiteColor];
            [button addSubview:view];
            [view release];
            if ([[self.nowArr objectAtIndex:i]isEqualToString:@"头条"]) {
                view.backgroundColor = [UIColor hongse];
            }
            view.tag = i + 1000;
            button.tag = i + 10000;
            [view release];
            
            // 对试图scroll进行刷新
            for (UIView *view1 in [self.scrollAll subviews]) {
                [view1 removeFromSuperview];
                
            }
            for (int i = 0; i < [self.nowArr count]; i++) {
                
                
                UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.view.bounds.size.height - self.view.bounds.size.height * 1 / 5)];
                [self.scrollAll addSubview:view2];
                view2.tag = i + 100;
                [view2 release];
                
                
            }
        }
        self.nowScroll.contentSize = CGSizeMake([self.nowArr count] * 75, 30);
        self.scrollAll.contentSize = CGSizeMake([self.nowArr count] * self.view.bounds.size.width, 0);
        self.scrollAll.contentOffset = CGPointMake(0, 0);
        [self reload];
        [self setupRefresh];
    }
}


- (void)search:(UIButton *)button
{
    Infor_Search_ViewController *search = [[Infor_Search_ViewController alloc]init];
    [self.navigationController pushViewController:search animated:YES];
    [search release];

}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if (self.change == NO) {
        [UIView animateWithDuration:0.3 animations:^{
            
            self.view1.frame = CGRectMake(0, 0, self.view.bounds.size.width, 0);
            self.changeButton.transform = CGAffineTransformMakeRotation(0);
            
        }];
        self.change = YES;
        // 选择栏目 返回时候 移除之前的子视图
        for (UIView *view in [self.nowScroll subviews]) {
            [view removeFromSuperview];
        }
        
        // 添加所有选择的button
        for (int i = 0; i < [self.nowArr count]; i++) {
            UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
            button.frame = CGRectMake(i * 55 + (i * 20), 0, 65, 40);
            [self.nowScroll addSubview:button];
            [button setTitle:[self.nowArr objectAtIndex:i] forState:UIControlStateNormal];
            button.backgroundColor = [UIColor whiteColor];
            [button addTarget:self action:@selector(nowButton:) forControlEvents:UIControlEventTouchUpInside];
            button.titleLabel.font = [UIFont systemFontOfSize:14];
            button.tintColor = [UIColor blackColor];
            
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(15, 37, 35, 3)];
            view.backgroundColor = [UIColor whiteColor];
            [button addSubview:view];
            [view release];
            if ([[self.nowArr objectAtIndex:i]isEqualToString:@"头条"]) {
                view.backgroundColor = [UIColor hongse];
            }
            view.tag = i + 1000;
            [view release];
            
            // 对试图scroll进行刷新
            for (UIView *view1 in [self.scrollAll subviews]) {
                [view1 removeFromSuperview];
                
            }
            for (int i = 0; i < [self.nowArr count]; i++) {
                
                UIView *view2 = [[UIScrollView alloc]initWithFrame:CGRectMake(i * self.view.bounds.size.width, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
                [self.scrollAll addSubview:view2];
                view2.tag = i + 100;
                //                scroll.contentSize = CGSizeMake(0, 1000);
                [view2 release];
                
            }
        }

    }
    self.nowScroll.contentSize = CGSizeMake([self.nowArr count] * 75, 30);
    self.scrollAll.contentSize = CGSizeMake([self.nowArr count] * self.view.bounds.size.width, 0);
    self.scrollAll.contentOffset = CGPointMake(0, 0);
    [self reload];
    [self setupRefresh];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
